package vashion.azeroth.back.controller.crm;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vashion.azeroth.api.controller.base.BaseController;
import vashion.azeroth.core.business.tran.pojo.BusinessAccount;
import vashion.azeroth.core.business.tran.pojo.BusinessTranDetail;
import vashion.azeroth.core.manager.business.tran.BusinessAccountManager;
import vashion.azeroth.core.manager.business.tran.BusinessTranDetailManager;
import vashion.azeroth.core.manager.personal.tran.PersonalTranDetailManager;
import vashion.azeroth.core.manager.personal.tran.PersonalVAccountManager;
import vashion.azeroth.core.personal.tran.pojo.PersonalTranDetail;
import vashion.azeroth.core.personal.tran.pojo.PersonalVAccount;
import vashion.azeroth.core.result.ApiResult;
import vashion.azeroth.core.service.tran.PersonalVAccountService;

import java.util.List;

@Controller
@RequestMapping("/back/crm")
public class CrmQueryController extends BaseController {

    @Autowired
    private PersonalVAccountService<PersonalVAccount> vaccountService;

    @Autowired
    private BusinessAccountManager businessAccountManager;

    @Autowired
    private BusinessTranDetailManager businessTranDetailManager;

    @Autowired
    private PersonalTranDetailManager tranDetailManager;

    @Autowired
    private PersonalVAccountManager vaccountManager;

    // ---------------------------------------------------------------------
    // 用于CRM后台查询使用
    // ---------------------------------------------------------------------

    @RequestMapping("queryVAccountBy.htm")
    @ResponseBody
    public ApiResult<List<PersonalVAccount>> queryVAccountBy(
            @ModelAttribute("personalVAccount") PersonalVAccount personalVAccount) {

        ApiResult<List<PersonalVAccount>> result = vaccountService.queryVAccountBy(personalVAccount);
        result.setTotalCount(vaccountManager.findCnt(personalVAccount));
        return result;

    }

    @RequestMapping("queryBusinessAccountBy.htm")
    @ResponseBody
    public ApiResult<List<BusinessAccount>> queryBusinessAccountBy(
            @ModelAttribute("businessAccount") BusinessAccount businessAccount) {

        List<BusinessAccount> baList = businessAccountManager
                .find(businessAccount);
        int totalCount = businessAccountManager.findCnt(businessAccount);
        return ApiResult.newSuccessResult(baList, totalCount);

    }

    @RequestMapping("queryBusinessTranDetailBy.htm")
    @ResponseBody
    public ApiResult<List<BusinessTranDetail>> queryBusinessTranDetailBy(
            @ModelAttribute("businessTranDetail") BusinessTranDetail businessTranDetail) {

        List<BusinessTranDetail> baList = businessTranDetailManager
                .find(businessTranDetail);

        return ApiResult.newSuccessResult(baList, baList.size());

    }

    @RequestMapping("queryTranDetailBy.htm")
    @ResponseBody
    public ApiResult<List<PersonalTranDetail>> queryTranDetailBy(
            @ModelAttribute("personalTranDetail") PersonalTranDetail personalTranDetail) {

        List<PersonalTranDetail> btList = tranDetailManager
                .find(personalTranDetail);

        return ApiResult.newSuccessResult(btList, btList.size());

    }

}
